/**
 * 
 */
package us.gaaoc.framework.dao;

import org.apache.log4j.Logger;
import org.hibernate.FetchMode;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;

import us.gaaoc.framework.model.Profile;

/**
 * @author tapshals
 * 
 */
public class ProfileDAOHibernate extends
		GenericHibernateDAO<Profile, String, ProfileDAO> implements ProfileDAO {

	private static final Logger LOG = Logger
			.getLogger(ProfileDAOHibernate.class);

	public Profile getPersonProfileByEmail(String email) {
		Profile profile = new Profile();
		try {
			// eagerly fetch the Profile Object
			profile = (Profile) getSession().createCriteria(Profile.class)
					.setFetchMode("*", FetchMode.SELECT).add(
							Restrictions.eq("email", email)).uniqueResult();
			if (profile != null) {
				Hibernate.initialize(profile.getPerson());
			}
		} catch (HibernateException he) {
			LOG.error(he);
			throw he;
		}
		return profile;
	}

	/*
	 * public Person getPersonByUserName(String userName){ Person person = null;
	 * try { // eagerly fetch the Person object person = (Person)
	 * getSession().createCriteria(Person.class) .setFetchMode("*",
	 * FetchMode.SELECT) .add(Restrictions.eq("userId", userName))
	 * .uniqueResult(); if(person != null){ //
	 * Hibernate.initialize(person.getProfile()); } } catch (HibernateException
	 * e) { LOG.error(e); throw e; } return person; }
	 */
}
